package com.hks360.car_treasure.fence;

import android.graphics.Color;
import android.util.Log;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.CircleOptions;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.Stroke;
import com.baidu.mapapi.model.LatLng;
import com.hks360.car_treasure.R;
import com.hks360.car_treasure.activity.EfenceActivity;
import com.hks360.library.util.PrefUtil;

/**
 * Created by rwq on 2016/5/25.
 */
public class GeoFence {
    public LatLng getCircle() {
        return circle;
    }

    private LatLng circle;


    public void setStyle(int style) {
        this.style = style;
    }

    private int style = 1;


    public int getRadius() {
        return radius;
    }

    private int radius = 50;
    private OverlayOptions arc;
    private int mZoom;

    public void createFence() {
        if (radius <= 500) {
            mZoom = 20;
        } else if (radius <= 1000) {
            mZoom = 16;
        } else if (radius <= 3000) {
            mZoom = 15;
        } else if (radius <= 5000) {
            mZoom = 14;
        } else if (radius <= 10000) {
            mZoom = 13;
        }
        Log.e("RWQ","mZoom" + mZoom+"");
        EfenceActivity.mBaiduMap.clear();
        try {
            addMarker();
            MapStatusUpdate mapStatus = MapStatusUpdateFactory.newLatLngZoom(circle, mZoom);
            EfenceActivity.mBaiduMap.animateMapStatus(mapStatus);
        }catch (Exception e){
            e.printStackTrace();
        }
        arc = null;
        Style(style);
        Log.e("RWQ","Style"+style+"" + ";radius" +radius+"");
        EfenceActivity.mBaiduMap.addOverlay(arc);
    }

    private void addMarker() {
        //定义Maker坐标点
        LatLng point = circle;
        //构建Marker图标
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.drawable.icon_marka);
        //构建MarkerOption，用于在地图上添加Marker
        OverlayOptions option = new MarkerOptions()
                .position(point)
                .icon(bitmap);
        //在地图上添加Marker，并显示
        EfenceActivity.mBaiduMap.addOverlay(option);
    }


    public void Style(int style){
        switch (style){
            case 1:
                arc = new CircleOptions().center(circle).stroke(new Stroke(5, Color.argb(0xFF,0x00,0x00,0x00))).fillColor(Color.argb(0x66,0xFF,0xF0,0xFF))
                        .radius(radius);
                break;
            case 2:
                arc = new CircleOptions().center(circle).stroke(new Stroke(5,Color.rgb(0xd8,0x00,0x00))).fillColor(Color.argb(0x66,0xe4,0xd4,0x48))
                        .radius(radius);
                break;
            case 3:
                arc = new CircleOptions().center(circle).stroke(new Stroke(5, Color.rgb(0xff,0xf0,0x00))).fillColor(Color.argb(0x66,0xe8,0x00,0x00))
                        .radius(radius);
                break;
        }
    }

    public void setRadius(int radius) {
        this.radius = radius;
    }

    public void setCircle(LatLng circle) {
        this.circle = circle;
    }


}